package com.openbravo.pos.printer.escpos;

import com.openbravo.pos.printer.DeviceTicket;
import java.awt.image.BufferedImage;

public class CodesStar extends Codes
{
  public static final byte[] INITSEQUENCE = { 27, 122, 1 };
  private static final byte[] CHAR_SIZE_0 = { 27, 105, 0, 0 };
  private static final byte[] CHAR_SIZE_1 = { 27, 105, 1, 0 };
  private static final byte[] CHAR_SIZE_2 = { 27, 105, 0, 1 };
  private static final byte[] CHAR_SIZE_3 = { 27, 105, 1, 1 };
  private static final byte[] BOLD_SET = { 27, 69 };
  private static final byte[] BOLD_RESET = { 27, 70 };
  private static final byte[] UNDERLINE_SET = { 27, 45, 1 };
  private static final byte[] UNDERLINE_RESET = { 27, 45, 0 };
  private static final byte[] OPEN_DRAWER = { 28 };
  private static final byte[] PARTIAL_CUT = { 27, 100, 48 };
  private static final byte[] IMAGE_BEGIN = { 27, 48 };
  private static final byte[] IMAGE_END = { 27, 122, 1 };
  private static final byte[] IMAGE_HEADER = { 27, 75 };
  private static final byte[] NEW_LINE = { 13, 10 };

  public byte[] getInitSequence()
  {
    return INITSEQUENCE;
  }

  public byte[] getSize0()
  {
    return CHAR_SIZE_0;
  }

  public byte[] getSize1()
  {
    return CHAR_SIZE_1;
  }

  public byte[] getSize2()
  {
    return CHAR_SIZE_2;
  }

  public byte[] getSize3()
  {
    return CHAR_SIZE_3;
  }

  public byte[] getBoldSet()
  {
    return BOLD_SET;
  }

  public byte[] getBoldReset()
  {
    return BOLD_RESET;
  }

  public byte[] getUnderlineSet()
  {
    return UNDERLINE_SET;
  }

  public byte[] getUnderlineReset()
  {
    return UNDERLINE_RESET;
  }

  public byte[] getOpenDrawer()
  {
    return OPEN_DRAWER;
  }

  public byte[] getCutReceipt()
  {
    return PARTIAL_CUT;
  }

  public byte[] getNewLine()
  {
    return NEW_LINE;
  }

  public byte[] getImageHeader()
  {
    return IMAGE_HEADER;
  }

  public int getImageWidth()
  {
    return 192;
  }

  public byte[] transImage(BufferedImage paramBufferedImage)
  {
    Codes.CenteredImage localCenteredImage = new Codes.CenteredImage( paramBufferedImage, getImageWidth());
    int i = localCenteredImage.getWidth();
    int j = (localCenteredImage.getHeight() + 7) / 8;
    byte[] arrayOfByte = new byte[IMAGE_BEGIN.length + (getImageHeader().length + 2 + i + getNewLine().length) * j + IMAGE_END.length];
    int k = 0;
    System.arraycopy(IMAGE_BEGIN, 0, arrayOfByte, k, IMAGE_BEGIN.length);
    k += IMAGE_BEGIN.length;
    for (int n = 0; n < localCenteredImage.getHeight(); n += 8)
    {
      System.arraycopy(getImageHeader(), 0, arrayOfByte, k, getImageHeader().length);
      k += getImageHeader().length;
      arrayOfByte[(k++)] = (byte)(i % 256);
      arrayOfByte[(k++)] = (byte)(i / 256);
      for (int i1 = 0; i1 < localCenteredImage.getWidth(); i1++)
      {
        int m = 0;
        for (int i2 = 0; i2 < 8; i2++)
        {
          m <<= 1;
          if (!localCenteredImage.isBlack(i1, n + i2))
            continue;
          m |= 1;
        }
        arrayOfByte[(k++)] = (byte)m;
      }
      System.arraycopy(getNewLine(), 0, arrayOfByte, k, getNewLine().length);
      k += getNewLine().length;
    }
    System.arraycopy(IMAGE_END, 0, arrayOfByte, k, IMAGE_END.length);
    k += IMAGE_END.length;
    return arrayOfByte;
  }

  public void printBarcode(PrinterWritter paramPrinterWritter, String paramString1, String paramString2, String paramString3)
  {
    if ("EAN13".equals(paramString1))
    {
      paramPrinterWritter.write(new byte[] { 27, 29, 97, 1 });
      paramPrinterWritter.write(new byte[] { 27, 98, 3 });
      if ("none".equals(paramString2))
        paramPrinterWritter.write(new byte[] { 1 });
      else
        paramPrinterWritter.write(new byte[] { 2 });
      paramPrinterWritter.write(new byte[] { 2 });
      paramPrinterWritter.write(new byte[] { 80 });
      paramPrinterWritter.write(DeviceTicket.transNumber(DeviceTicket.alignBarCode(paramString3, 13).substring(0, 12)));
      paramPrinterWritter.write(new byte[] { 30 });
      paramPrinterWritter.write(new byte[] { 27, 29, 97, 0 });
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.printer.escpos.CodesStar
 * JD-Core Version:    0.6.0
 */